package com.lu.component.http.proxy.support.flow;

import com.lu.component.rpc.annotations.RpcApiRequest;

import java.util.function.Supplier;

/**
 * RPC流控
 *
 * @author: zhanglu
 * @date: 2023/8/30 16:11
 * @modify: 修改人信息, 修改内容 2023/8/30 16:11
 */
public abstract class RpcFlowControlAbstract {

    /**
     * 接口配置
     */
    protected RpcApiRequest rpcApiRequest;

    public RpcFlowControlAbstract(RpcApiRequest rpcApiRequest) {
        this.rpcApiRequest = rpcApiRequest;
    }

    /**
     * 执行流控请求
     * @param key       流控key
     * @param supplier  rpc请求执行逻辑
     * @param fallback  rpc请求失败降级
     * @param <T>
     * @return
     */
    public abstract <T> T execute(String key, Supplier<T> supplier, Supplier<T> fallback);
}
